package com.dongdongshop.testcontroller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @Description
 * @ClassName TestSessionController
 * @Author RC
 * @date 2020.12.21 13:07
 */
@Controller
public class TestSessionController {

    @RequestMapping("hello")
    @ResponseBody
    public String hello(HttpServletRequest request){
        HttpSession session = request.getSession();
        //放入session
        session.setAttribute("hello","hello");
        return "hello";
    }
    @RequestMapping("getSession")
    @ResponseBody
    public String getSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        //获取session
        return session.getAttribute("hello").toString();
    }
}
